package zhai.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
//动态代理
public class ZhaiLogInvocationHandler implements InvocationHandler {

    private Object obj;

    public void setObj(Object obj) {
        this.obj = obj;
    }

    public Object getProxy() {
        return Proxy.newProxyInstance(this.getClass().getClassLoader(), obj.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("方法信息：" + method);
        System.out.println("入参信息：" + args);
        Object result = method.invoke(obj, args);
        System.out.println("方法返回："+ result);
        return result;
    }

}
